package cn.jia.spring4.aspect;

import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**记录磁道的播放次数
 * Created by jia on 2018/4/2.
 */
//@Component
@Aspect
public class TrackCounter {
    //记录磁道播放次数
    private Map<Integer,Integer> trackCounts = new HashMap<Integer, Integer>();
    @Pointcut("execution(* cn.jia.spring2.pojo.InterfaceImpl.BlankDisc.playTrack(int,int))"+
            "&& args(num,x)")
    //注意此处的number，要和args中的number要一致
    public void trackCount(int num,int x){}
    //注意：此处的参数名要和下面方法参数名要一致
    @AfterReturning("trackCount(number,y)")
    //每次播放之后，number++
    public void countTrack(int number,int y){
        number++;
        System.out.println("number = "+number);
        System.out.println("x = "+y);
    }
}
